<template>
	<view class="vip">
		<view class="box">
			<view class="infoli">
				<view class="left">
					转账金额
				</view>
				<view class="right">
					<input type="number" placeholder="请输入金额" v-model="num" @input="getShopTransfer">
				</view>
			</view>
		</view>
		<view class="box">
			<view class="infoli">
				<view class="left">
					支付密码
				</view>
				<view class="right">
					<input type="password" placeholder="请输入支付密码" v-model="password">
				</view>
			</view>
		</view>
		<view class="box">
			<view class="infoli">
				<view class="left">
					转账类型
				</view>
				<view class="right">
					<radio-group @change="change">
						<label>
							<radio value="1" :checked="value == 1" /><text>余额</text>
						</label>
						<label v-if="type ==2">
							<radio value="2" :checked="value == 2" /><text>积分</text>
						</label>
					</radio-group>
				</view>
			</view>
		</view>
		<view class="tips">
			<text>可用余额 : {{user.balance_4}}</text>
			<text v-if="type == 2">可用积分 : {{user.balance_1}}</text>
		</view>
		<view class="tips" style="color: #FF3C29;font-size: 14px;font-weight: bold;">
			<text style="margin-right: 10px;">到店自提</text> <text>享受会员价</text>
		</view>
		<view>
			<button class="btn" :loading="loading" :disabled="loading" @click="transfer">去支付</button>
		</view>
	</view>
</template>

<script>
	import {
		ShopTransfer,
		UserInfo,
		getShopTransfer
	} from "@/api/api.js"
	export default {
		data() {
			return {
				type: '',
				num: '',
				password: '',
				loading: false,
				user: [],
				id: '',
				reward: 0,
				value: 1
			}
		},
		onLoad(e) {
			if (e.type) this.type = e.type
			if (e.id) this.id = e.id
			// this.commonParam()
			this.UserInfo()
			this.getShopTransfer()
		},
		methods: {
			getShopTransfer() {
				getShopTransfer({
					store_id: this.id,
				}).then(res => {
					if (res.status == 1) {
						this.reward = res.data.reward
					}
				})
			},
			change(e) {
				this.value = e.detail.value
			},
			UserInfo() {
				UserInfo().then(res => {
					if (res.status == 1) {
						this.user = res.data
					}
				})
			},
			transfer() {
				var that = this
				if (that.num == '') {
					return uni.$showMsg('请输入金额')
				}
				if (that.password == '') {
					return uni.$showMsg('请输入支付密码')
				}
				that.loading = true
				ShopTransfer({
					num: that.num,
					store_id: that.id,
					type: that.value,
					password_pay: that.password
				}).then(res => {
					that.loading = false
					uni.$showMsg(res.message)
					if (res.status == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 500)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-top: 10px;
		background: #f2f2f2;
	}

	.uni-select {
		border: 1px solid #eee !important;
		height: 40px !important;
		border-bottom: unset;
	}

	.box {
		width: 96%;
		margin: 0 auto;
		margin-top: 10px;
		background: #fff;
		border-radius: 5px;
		padding: 10px 12px;
		box-sizing: border-box;
		box-shadow: 0 0 5px #d5d5d5;
		display: flex;
		align-items: center;

		.title {
			font-weight: bold;
			font-size: 15px;
		}

		.infoli {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 2px 0;
			flex: 1;

			.left {
				width: 80px;
				font-weight: bold;
			}

			.right {
				width: calc(100% - 80px);
				display: flex;
				align-items: center;

				input {
					font-size: 14px;
				}

				label {
					margin-bottom: 0;
				}
			}

			.reward {
				font-weight: bold;
				color: #FF3C29;
			}
		}

		.inputli {
			margin-top: 10px;

			input {
				font-size: 16px;
				padding: 10px 0;
				color: #FF3C29;
			}
		}
	}

	.tips {
		width: 92%;
		margin: 0 auto;
		color: #777;
		font-size: 12px;
		margin-top: 10px;

		text {
			margin-right: 15px;
		}
	}

	.btn {
		width: 90%;
		color: #fff;
		font-size: 15px;
	}
</style>